/*
 * Copyright 2014-2017 Toradex AG
 * Copyright 2012 Freescale Semiconductor, Inc.
 * Copyright 2011 Linaro Ltd.
 *
 * This file is dual-licensed: you can use it either under the terms
 * of the GPL or the X11 license, at your option. Note that this dual
 * licensing only applies to this file, and not this project as a
 * whole.
 *
 *  a) This file is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License
 *     version 2 as published by the Free Software Foundation.
 *
 *     This file is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 * Or, alternatively,
 *
 *  b) Permission is hereby granted, free of charge, to any person
 *     obtaining a copy of this software and associated documentation
 *     files (the "Software"), to deal in the Software without
 *     restriction, including without limitation the rights to use,
 *     copy, modify, merge, publish, distribute, sublicense, and/or
 *     sell copies of the Software, and to permit persons to whom the
 *     Software is furnished to do so, subject to the following
 *     conditions:
 *
 *     The above copyright notice and this permission notice shall be
 *     included in all copies or substantial portions of the Software.
 *
 *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *     OTHER DEALINGS IN THE SOFTWARE.
 */

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include "imx6q.dtsi"
#include "imx6qdl-apalis.dtsi"

/ {
	model = "Toradex Apalis iMX6Q/D Module on Apalis Evaluation Board";
	compatible = "toradex,apalis_imx6q-eval", "toradex,apalis_imx6q",
		     "fsl,imx6q";

	aliases {
		i2c0 = &i2c1;
		i2c1 = &i2c3;
		i2c2 = &i2c2;
		rtc0 = &rtc_i2c;
		rtc1 = &snvs_rtc;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	gpio-keys {
		compatible = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_keys>;

		wakeup {
			label = "Wake-Up";
			gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_WAKEUP>;
			debounce-interval = <10>;
			wakeup-source;
		};
	};

	lcd_display: disp0 {
		compatible = "fsl,imx-parallel-display";
		#address-cells = <1>;
		#size-cells = <0>;
		interface-pix-fmt = "rgb24";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_ipu1_lcdif>;
		status = "okay";

		port@0 {
			reg = <0>;

			lcd_display_in: endpoint {
				remote-endpoint = <&ipu1_di1_disp1>;
			};
		};

		port@1 {
			reg = <1>;

			lcd_display_out: endpoint {
				remote-endpoint = <&lcd_panel_in>;
			};
		};
	};

	panel: panel {
		/*
		 * edt,et057090dhu: EDT 5.7" LCD TFT
		 * edt,et070080dh6: EDT 7.0" LCD TFT
		 */
		compatible = "edt,et057090dhu";
		backlight = <&backlight>;
		power-supply = <&reg_3v3_sw>;

		port {
			lcd_panel_in: endpoint {
				remote-endpoint = <&lcd_display_out>;
			};
		};
	};

	reg_pcie_switch: regulator-pcie-switch {
		compatible = "regulator-fixed";
		regulator-name = "pcie_switch";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		gpio = <&gpio1 2 GPIO_ACTIVE_HIGH>;
		startup-delay-us = <100000>;
		enable-active-high;
		status = "okay";
	};

	reg_3v3_sw: regulator-3v3-sw {
		compatible = "regulator-fixed";
		regulator-name = "3.3V_SW";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};
};

&backlight {
	brightness-levels = <0 127 191 223 239 247 251 255>;
	default-brightness-level = <1>;
	power-supply = <&reg_3v3_sw>;
	status = "okay";
};

&can1 {
	xceiver-supply = <&reg_3v3_sw>;
	status = "okay";
};

&can2 {
	xceiver-supply = <&reg_3v3_sw>;
	status = "okay";
};

&hdmi {
	status = "okay";
};

/* I2C1_SDA/SCL on MXM3 209/211 (e.g. RTC on carrier board) */
&i2c1 {
	status = "okay";

	pcie-switch@58 {
		compatible = "plx,pex8605";
		reg = <0x58>;
	};

	/* M41T0M6 real time clock on carrier board */
	rtc_i2c: rtc@68 {
		compatible = "st,m41t0";
		reg = <0x68>;
	};
};

/*
 * I2C3_SDA/SCL (CAM) on MXM3 pin 201/203 (e.g. camera sensor on carrier
 * board)
 */
&i2c3 {
	status = "okay";
};

&ipu1_di1_disp1 {
	remote-endpoint = <&lcd_display_in>;
};

&ldb {
	status = "okay";
};

&pcie {
	/* active-high meaning opposite of regular PERST# active-low polarity */
	reset-gpio = <&gpio1 28 GPIO_ACTIVE_HIGH>;
	reset-gpio-active-high;
	vpcie-supply = <&reg_pcie_switch>;
	status = "okay";
};

&pwm1 {
	status = "okay";
};

&pwm2 {
	status = "okay";
};

&pwm3 {
	status = "okay";
};

&pwm4 {
	status = "okay";
};

&reg_usb_otg_vbus {
	status = "okay";
};

&reg_usb_host_vbus {
	status = "okay";
};

&sata {
	status = "okay";
};

&sound_spdif {
	status = "okay";
};

&spdif {
	status = "okay";
};

&uart1 {
	status = "okay";
};

&uart2 {
	status = "okay";
};

&uart4 {
	status = "okay";
};

&uart5 {
	status = "okay";
};

&usbh1 {
	vbus-supply = <&reg_usb_host_vbus>;
	status = "okay";
};

&usbotg {
	vbus-supply = <&reg_usb_otg_vbus>;
	status = "okay";
};

/* MMC1 */
&usdhc1 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_usdhc1_4bit &pinctrl_usdhc1_8bit &pinctrl_mmc_cd>;
	cd-gpios = <&gpio4 20 GPIO_ACTIVE_LOW>;
	status = "okay";
};

/* SD1 */
&usdhc2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_usdhc2 &pinctrl_sd_cd>;
	cd-gpios = <&gpio6 14 GPIO_ACTIVE_LOW>;
	status = "okay";
};

&iomuxc {
	/*
	 * Mux the Apalis GPIOs
	 */
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_apalis_gpio1 &pinctrl_apalis_gpio2
		     &pinctrl_apalis_gpio3 &pinctrl_apalis_gpio4
		     &pinctrl_apalis_gpio5 &pinctrl_apalis_gpio6
		     &pinctrl_apalis_gpio7 &pinctrl_apalis_gpio8
		    >;
};
